class Solution {
    public static void main(String[] args) {
        Solution s = new Solution();
        int[] arr = new int[]{1,2,1,3,5,6,4};
        s.findPeakElement(arr);
    }

    public int findPeakElement(int[] nums) {
        /**
         * 寻找峰值
         * 使用普通双指针解法
         * */
        // 1 预处理
        int n = nums.length;
        if(n == 1) return 0;

        // 2 双指针
        long left = 0;
        long right = n - 1;
        while(left < right) {
            int mid = (int)(left + (right - left) / 2);
            if(nums[mid] < nums[mid + 1]) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }

        // 3 返回值
        return (int)left;
    }
}
